﻿
appRoot.controller('ConfigController', function ($scope, $location, $resource) {

    //var Parameter = $resource('/api/parameters/:Id', { 'Id': 1 }, { get: { method: 'GET' } });

    $scope.selectedEndpoints = [];

    $scope.$watchCollection('selectedEndpoints', function () {
        $scope.selectedEndpoint = angular.copy($scope.selectedEndpoints[0]);
    });

    $scope.endpointGrid = {
        data: 'endpointList',
        multiSelect: false,
        selectedItems: $scope.selectedEndpoints,
        enableColumnResize: false,
        columnDefs: [
            { field: 'name', displayName: 'Profile Name' },
                { field: 'address', displayName: 'IP' },
                { field: 'port', displayName: 'Port' },
                { field: 'category', displayName: 'Category' }
                // { field: '', cellTemplate: '<button class="btn btn-mini btn-danger" ng-click="">Delete</button>' }
        ]
    };

    $scope.getEndpoints = function () {

        $scope.fusionParameter = null;
        $scope.securityParameter = null;

        var endpointResource = $resource('/api/parameters', {}, { update: { method: 'PUT' } });

        $scope.endpointList = [];

        endpointResource.query(function (data) {
            $scope.endpointList = [];
            angular.forEach(data, function (endpointData) {
                $scope.endpointList.push(endpointData);
            });
        });
    };

    $scope.getFusionParameter = function () {
        //$scope.newParameter = Parameter.get({ Id: 1 });
        $scope.endpointList = null;
        $scope.fusionParameter = new Object();
        $scope.securityParameter = null;
        $scope.selectedEndpoint = null;
    };
    
    $scope.getSecurityParameter = function () {
        $scope.endpointList = null;
        $scope.fusionParameter = null;
        $scope.securityParameter = new Object();
        $scope.selectedEndpoint = null;
    };
    /*
    parameterResource.get({ parameterId: 1 }, function (d) {
        alert(d.Address);
    });
    
    $scope.updateParameter = function (parameter) {
        parameterResource.update(parameter, function (updatedParameter) {
            $scope.parameterData.radarAddress = updatedParameter.radarAddress;
            $scope.parameterData.radarPort = updatedParameter.radarPort;
            $scope.parameterData.adsbAddress = updatedParameter.adsbAddress;
            $scope.parameterData.adsbPort = updatedParameter.adsbPort;
            $scope.parameterData.udpBufferSize = updatedParameter.udpBufferSize;
            $scope.parameterData.positionResolution = updatedParameter.positionResolution;
            $scope.parameterData.altitudeResolution = updatedParameter.altitudeResolution;
            $scope.parameterData.fusionRate = updatedParameter.fusionRate;
        });
    };
    */
    
    $scope.init = function () {
        $scope.getEndpoints();
    }
    
});